<?php

include_package( 'Xml' );

class XmlDatabaseTableElement extends XmlElement {

	function XmlDatabaseTableElement( &$oConfiguration, &$oTable ) {

		$this->XmlElement( 'TABLE' );
		$this->AddAttribute( 'NAME', $oTable->GetName() );
		$this->AddAttribute( 'ID'  , $oTable->GetName() );
		
		if ( $oConfiguration->GetProperty( 'ShowColumns' ) ) {
			foreach( $oTable->GetColumns() as $oThisColumn ) {
				$this->AddElement( new XmlDatabaseColumnElement( $oConfiguration, $oThisColumn ) );
			}
		}
	
		if ( $oConfiguration->GetProperty( 'ShowPrimaryKeys' ) ) {
			$this->AddElement( new XmlDatabasePrimaryKeyElement( $oConfiguration, $oTable->GetPrimaryKey() ) );
		}
		
		if ( $oConfiguration->GetProperty('ShowForeignKeys') && $oTable->HasForeignKeysFrom() ) {
			$this->AddElement( new XmlDatabaseForeignKeyListElement( $oConfiguration, $oTable->GetForeignKeysFromThisTable(), 'From' ) );
		}
		
		if ( $oConfiguration->GetProperty('ShowForeignKeys') && $oTable->HasForeignKeysReferencing() ) {
			$this->AddElement( new XmlDatabaseForeignKeyListElement( $oConfiguration, $oTable->GetForeignKeysReferencingThisTable(), 'To' ) );
		}
	}
}

require_once( 'XmlDatabaseColumnElement.php' );
require_once( 'XmlDatabasePrimaryKeyElement.php' );
	
?>
